package demo1;

public class LeetCode1004 {
    public int longestOnes(int[] nums, int k) {
        int n = nums.length , len = 0;
        int[] hash = new int[2];
        //逆向思考：一个子数组里0的个数不超过k个
        for(int left = 0 , rigth = 0; rigth < n; rigth++) {
            hash[nums[rigth]]++;
            while(hash[0] > k) hash[nums[left++]]--;
            len = Math.max(len , rigth - left + 1);
        }
        return len;
    }
}
